#ifndef __VOREST_HTML_READER__
#define __VOREST_HTML_READER__

#include <string>
#include <fstream>
#include <iostream>
#include <vector>
#include <exception>

#include "VorestTreeInfo.h"

namespace dataengine
{
	/** Class used to load Vorest-generated forest HTML files */
	class VorestHtmlReader
	{
		public:	
			/** Constructor. Just stores the fileName */
			VorestHtmlReader(std::string fileName);
			/** Checks if the file can be loaded */
			bool canLoadFile();
			/** Reads the forest info from the file */
			std::vector<VorestTreeInfo> readFile();

		private:
			enum TokenType{Token_TD,Token_TR,Token_TR_End,Token_Other};

			std::string getNextLine();
			int tokenType(const std::string& line);
			std::string getTDContents(const std::string &line);
			VorestTreeInfo readNextTreeInfo();

			std::ifstream m_file;
			std::string m_fileName;

			class HtmlParseException : public std::exception
			{
				public:
					HtmlParseException(std::string message) : m_message(message){}
					~HtmlParseException()throw(){}
				protected:
					virtual const char* what() const throw(){ return m_message.c_str(); }
					std::string m_message;
			};
	};
}
#endif

